﻿import React from 'react';
import ReactDOM from 'react-dom';
import mirror, { actions, connect, Link } from 'mirrorx';
import { List } from 'antd-mobile';

const Item = List.Item;
const Brief = Item.Brief;

import { FormattedMessage} from 'react-intl';


class App extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			bankcardList: []
		}
	}

	componentDidMount() {
		T.fetch({
				url: "/bank/list.json",
				data: {},
			}).then((res) => {
				if (res.success) {
					this.setState({
						bankcardList:res.value
					})
				}
		});
	}

	bankcardInfo = (cardNo,bankInfoId,userName,bankName) => {//跳转到银行卡信息页面（可进行银行卡修改操作）
		let choose = T.urlQuery("choose");		
		if(choose == 1){			
			let urlParam = '?cardNo=' + cardNo + "&bankInfoId=" + bankInfoId + "&userName=" + userName +"&bankName=" + bankName;
			location.href = T.urlQuery("backUrl") + urlParam;
		}
		else{
			actions.routing.push({
			pathname: 'bankcard-info',
			search: '?cardNo=' + cardNo + "&bankInfoId=" + bankInfoId
		})
		}
		
	}

	render() {
		const bankcardList = this.state.bankcardList;
		return (<div className="bankcard-list">
			<div className="top"><FormattedMessage id='bankcard_info' defaultMessage='银行卡信息'/>   <Link className='add' to="bankcard-manage" >+</Link></div>
			<List className="my-list">
			{
                bankcardList.map((item)=>
				<Item arrow="horizontal" multipleLine onClick={() => this.bankcardInfo(item.cardNo,item.bankInfoId,item.userName,item.bankName)} key={item.cardNo}>
					{item.bankName} <Brief>{item.cardNo}</Brief>
				</Item>
			)}			
			</List>
		</div>)
	}
}

export default App;